<?php
/**
 * CreateTime: 2024/1/8 17:22
 * User:LinQ
 */

namespace App\Factory\Email;

use Symfony\Component\Mailer\Mailer;
use Symfony\Component\Mailer\Transport;
use Symfony\Component\Mime\Email;

class NetEaseEmailSender implements EmailSenderInterface
{
    public function sendEmail($toEmail, $title, $data,$args=[],$debug=false): bool
    {
        try {
            $configInfo = config('openapi.163_email_stmp');
            $dsn = "smtp://".$configInfo['from_email']. ":".$configInfo['password']."@" .$configInfo['host'].":".$configInfo['port'];
            $transport = Transport::fromDsn($dsn);
            $mailer = new Mailer($transport);
            $message = (new Email())
                ->from($configInfo['from_email'])
                ->to($toEmail)
                ->subject($title)
                ->html($data);
            $mailer->send($message);
            return true;
        }catch (\Exception $exception){
            if($debug){
                dd($exception);
            }
            return false;
        }
    }
}